package codeTopPractice;

public class 最大连续子数和 {

    public static void main(String[] args) {

    }

    public static int maxSubArray(int[] nums){

        if(nums.length == 0) return 0;
        if(nums.length == 1) return nums[0];

        int i = 1;
        int curr = nums[0];
        int max = curr;
        while (i < nums.length){
            if(curr <= 0){
                curr = nums[i];
                max = max > curr ? max : curr;
                i++;
                continue;
            }else if(curr > 0){
                curr = curr + nums[i];
                max = max > curr ? max : curr;
                i++;
            }
        }

        return max;
    }

}
